package com.supergdtop.www.run.tools;

import java.math.BigDecimal;

/**
 * 数字相关工具
 * Created by Asum on 2016/7/8 0008.
 */
public class NumberTools {
    /**
     * 转成double
     *
     * @param numberString
     * @param precision    精确到小数点几位
     * @return
     */
    public static double toDouble(String numberString, int precision) {
        try {
            BigDecimal bd = new BigDecimal(numberString);
            bd = bd.setScale(precision, BigDecimal.ROUND_HALF_UP);
            return bd.doubleValue();
        } catch (Exception e) {
            e.printStackTrace();
            XLog.e("强转数字失败");
            return 0;
        }
    }
}
